package com.wy.io;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

/**
 * @author 美女
 * @date 2022/05/09 19:36
 **/
public class ReadFile3 {
    public static void main(String[] args) throws IOException {
        try (InputStream is = new FileInputStream("hello.txt")) {
            byte[] buf = new byte[1024];
            while (true) {
                int n = is.read(buf);
                if (n == -1) {
                    break;
                }
                System.out.println(Arrays.toString(Arrays.copyOf(buf, n)));//使用copyOf，读取都是有效内容（0不会出现）
            }
        }
    }
}
